package cn.fatgod.learn.thymeleaf.binder;

import cn.fatgod.learn.thymeleaf.standard.interfaces.Bind;
import cn.fatgod.learn.thymeleaf.standard.interfaces.IDataBinder;
import cn.fatgod.learn.thymeleaf.standard.interfaces.Importable;
import cn.fatgod.learn.thymeleaf.standard.enums.PropertyType;
import cn.hutool.core.util.StrUtil;

import java.util.Collections;
import java.util.List;

/**
 * 属性数据绑定器
 */
@Bind
public class PropertyDataBinder implements IDataBinder, Importable {
    /**
     * 键
     */
    private final String key;

    /**
     * 值
     */
    private final String value;

    /**
     * 类型
     */
    private final PropertyType type;

    /**
     * 导入路径
     */
    private final String importPath;

    private PropertyDataBinder(String key, String value, PropertyType type, String importPath) {
        this.key = key;
        this.value = value;
        this.type = type;
        this.importPath = importPath;
    }

    public PropertyDataBinder(String key, String value) {
        this(key, value, PropertyType.STR, StrUtil.EMPTY);
    }

    public PropertyDataBinder(String key, String value, PropertyType type) {
        this(key, value, type, StrUtil.EMPTY);
    }

    public PropertyDataBinder(String key, String value, String importPath) {
        this(key, value, PropertyType.TEXT, importPath);
    }

    @Override
    public List<String> getImportPaths() {
        return StrUtil.isEmpty(this.importPath) ? Collections.emptyList() :
                Collections.singletonList(this.importPath);
    }

    public String getKey() {
        return key;
    }

    public String getValue() {
        return value;
    }

    public PropertyType getType() {
        return type;
    }
}
